/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.List;
import queenb.net.entitybean.F000;
import queenb.web.store.F000Store;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class F000Controller extends QueenbController{
    private int pf000;
    private String fv001;
    private String fv002;
    private F000Store f000Store;
    
    public F000Controller(){
        f000Store = new F000Store();
        Object action = getRequest().getParameter("action");
        Object pf000Object = getRequest().getParameter("pf000");
        if(action != null)
        {
            if(action.equals("edit"))
            {
                this.pf000 = Util.parseInt(pf000Object);
                getDetailEditF000(pf000);
            }
        }
    }
    
    public void updateF000(){
        try {
            int count = f000Store.updateF000(pf000, getLogin().getModule(), getLogin().getCompanyNo(), fv001, fv002, 0, 0, getLogin().getUserName());
            if (count > 0) {
                showGlobalReport(true, getResourceString("success"));
            } else {
                showGlobalReport(true, getResourceString("error"));
            }
       
        
        sendRedirectUrlTab("setting.jsp?tab=header21&linkF000="+Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }
    public void getDetailEditF000(int id) {
        try {
            List<F000> listF000Edit = getListAllF000();
            if (listF000Edit.size() > 0) {
                for (int i = 0; i < listF000Edit.size(); i++) {
                    if (listF000Edit.get(i).getPf000() == id) {
                        this.fv001 = listF000Edit.get(i).getFv001();
                        this.fv002 = listF000Edit.get(i).getFv002();
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
        }
    }
    
     public List<F000> getListAllF000() {

        try {

            List<F000> list = f000Store.getListCityALL(getLogin().getModule(),getLogin().getCompanyNo(),getLogin().getUserName());
            return list;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }

    }

    /**
     * @return the pf000
     */
    public int getPf000() {
        return pf000;
    }

    /**
     * @param pf000 the pf000 to set
     */
    public void setPf000(int pf000) {
        this.pf000 = pf000;
    }

    /**
     * @return the fv001
     */
    public String getFv001() {
        return fv001;
    }

    /**
     * @param fv001 the fv001 to set
     */
    public void setFv001(String fv001) {
        this.fv001 = fv001;
    }

    /**
     * @return the fv002
     */
    public String getFv002() {
        return fv002;
    }

    /**
     * @param fv002 the fv002 to set
     */
    public void setFv002(String fv002) {
        this.fv002 = fv002;
    }
}
